<%@ page import="java.util.UUID"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp" %>
<%
    String uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
%>
<style type="text/css">
	.addOrderBtnCss{
		color: red;font-size: 14px;font-weight: bold;cursor: pointer; padding: 2px;
	}
	.riskWO{
		display: none;
	}
	.queryInputLabel{
		color: orange;
	}
	.autoInputLabel{
		color: #3399FF;
	}
</style>
<div class="container-fluid am-margin-top">
    	<form id="workOrderByUserForm">
	        <input type="hidden" name="id"/>
	        <input type="hidden" name="his_yhzh"/>
	        <!-- 客户信息部分 -->
	        <ul class="nav nav-tabs" role="tablist">
				<li role="presentation" class="active">
					<a href="#${uuid}_clientDataTab" role="tab" data-toggle="tab">
						客户信息
					</a>
				</li>
			</ul>
			<div class="tab-content">
				<div role="tabpanel" class="tab-pane fade in  active am-margin-top-sm" id="${uuid}_clientDataTab">
			        <div class="row">
						<div class="col-md-3">
							<div class="form-group"><label>来电号码</label>
								<input type="text" name="ldhm" class="form-control" check-type="required">
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>创建时间</label>
								<div>2016-09-09 12:12:12</div>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>通话时长</label>
								<div>53秒</div>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>业务来源</label>
				                <pf:dataDic var="item" dicCode="YWLY">
				                </pf:dataDic>
				                <div>电话呼入</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-3">
							<div class="form-group"><label>客户姓名</label>
								<input type="text" name="khxm" class="form-control" check-type="required">
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>客户类型</label>
								<select class="form-control"  name="khlx" check-type="required">
					                <pf:dataDic var="item" dicCode="KHLX">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>客户语言</label>
								<select class="form-control"  name="khyy" check-type="required">
					                <pf:dataDic var="item" dicCode="KHYY">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group" style="padding-top: 25px;">
								<!-- 
								<a href="javascript:void(0)" id="searchOrderBt" class="btn btn-warning">保存更新</a>
								 -->
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- 客户信息部分结束 -->
		</form>
		<div class="addOrderBtnCss">新增工单+</div>
		<ul class="nav nav-tabs" role="tablist" id="orderNav">
			<li role="presentation" class="active">
				<a href="#${uuid}_fieldDataTab" role="tab" data-toggle="tab">
					新建工单1
				</a>
			</li>
		</ul>
		<div class="tab-content" id="orderTab">
				<div role="tabpanel" class="tab-pane fade in  active am-margin-top-sx orderPane" id="${uuid}_fieldDataTab" label="新建工单1">
		   	  	  <form name="workOrderForm">
		   	  	   　 <!-- 公共上部分 -->
					<div class="row">
						<div class="col-md-3">
							<div class="form-group"><label>业务类型</label>
								<select class="form-control"  name="ywlx" check-type="required">
					                <pf:dataDic var="item" dicCode="YWLX">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>子业务类型</label>
								<select class="form-control"  name="zywlx" check-type="required">
					                <pf:dataDic var="item" dicCode="ZYWLX">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>疑难投诉</label>
								<select class="form-control"  name="ynts" check-type="required">
					                <pf:dataDic var="item" dicCode="YNTS">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<!-- 客服工单部分 -->
						<div class="col-md-3 serviceWO">
							<div class="form-group"><label>客户诉求</label>
								<select class="form-control"  name="khsq" check-type="required">
					                <pf:dataDic var="item" dicCode="KHSQ">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<!-- 客服工单部分结束 -->
					</div>
					<!-- 公共上部分结束 -->
					
					<!-- 风控工单部分 -->
					<div class="row riskWO">
						<div class="col-md-3">
							<div class="form-group"><label class="autoInputLabel">交易手机号是否银行预留手机号</label>
								<select class="form-control"  name="jysjhsfyhylsjh" disabled="disabled">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>交易手机号是否属于本人</label>
								<select class="form-control"  name="jysjhmsfbr" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>呼叫转移</label>
								<select class="form-control"  name="hjzy" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>短信拦截</label>
								<select class="form-control"  name="dxlj" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
					</div>
					<div class="row riskWO">
						<div class="col-md-3">
							<div class="form-group"><label>接收呼转号码</label>
								<input type="text" class="form-control"  name="jszyhm"/>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label class="autoInputLabel">受益人</label>
								<input type="text" class="form-control"  name="syr" readonly="readonly"/>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>是否认识受益人</label>
								<select class="form-control"  name="sfrssydx" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>是否认识交易手机</label>
								<select class="form-control"  name="sfrsjysj" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
					</div>
					<div class="row riskWO">
						<div class="col-md-3">
							<div class="form-group"><label class="autoInputLabel">呼转号码归属地</label>
								<input type="text" class="form-control"  name="hzhmgsd" readonly="readonly"/>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label class="autoInputLabel">呼转号码运营商</label>
								<input type="text" class="form-control"  name="hzhmyys" readonly="readonly"/>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label class="autoInputLabel">受益人手机号</label>
								<input type="text" class="form-control"  name="syrsjh" readonly="readonly"/>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label class="autoInputLabel">受益人手机号归属地</label>
								<input type="text" class="form-control"  name="syrsjhgsd" readonly="readonly"/>
							</div>
						</div>
					</div>
					<div class="row riskWO">
						<div class="col-md-3">
							<div class="form-group"><label>与受益人关系</label>
								<select class="form-control"  name="ysydxgx" check-type="required">
					                <pf:dataDic var="item" dicCode="QSGX">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>手机品牌</label>
								<select class="form-control"  name="sjpp" check-type="required">
					                <pf:dataDic var="item" dicCode="SJPP">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>手机系统</label>
								<select class="form-control"  name="sjxt" check-type="required">
					                <pf:dataDic var="item" dicCode="SJXT">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>银行卡信息泄露</label>
								<select class="form-control"  name="yhkxxxl" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
					</div>
					<div class="row riskWO">
						<div class="col-md-3">
							<div class="form-group"><label>ID是否被盗</label>
								<select class="form-control"  name="idsfxl" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>ID注册邮箱</label>
								<select class="form-control"  name="idzcyx" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>是否报警</label>
								<select class="form-control"  name="sfbj" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label>手机系统是否越狱</label>
								<select class="form-control"  name="sjsfyy" check-type="required">
					                <pf:dataDic var="item" dicCode="SF">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
					</div>
					<div class="row riskWO">
						<div class="col-md-12">
							<div class="form-group"><label>银行账号绑定业务情况</label>
								<pf:dataDic var="item" dicCode="BDYW">
					                    &nbsp;&nbsp;${item.name}&nbsp;<input type="checkbox" name="yhkbdyw" value="${item.value}">
					            </pf:dataDic>
					            <input type="text" class="form-control"  name="bdywbc" placeholder="其他说明"/>
							</div>
						</div>
					</div>
					<!-- 风控工单部分结束 -->
					
					<!-- 公共下部分 -->
					<div class="row">
						<div class="col-md-12">
							<div class="form-group"><label>客户投诉</label>
								<textarea name="khtsbt"  class="form-control" check-type="required"></textarea>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="form-group"><label>受理情况</label>
								<textarea name="slqk"  class="form-control" check-type="required"></textarea>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-4">
							<div class="form-group"><label class="autoInputLabel">关联交易笔数</label>
								<input type="text" class="form-control" id="tradCount" name="gljybs" value="0" readonly="readonly"/>
							</div>
						</div>
						<div class="col-md-4">
							<div class="form-group"><label class="autoInputLabel">关联交易金额</label>
								<input type="text" class="form-control" id="tradJe" name="gljyje" value="0.00" readonly="readonly"/>
							</div>
						</div>
						<div class="col-md-3">
							<div class="form-group"><label class="autoInputLabel">关联交易</label>
								<div id="joinTrad">
									
								</div>
								<input type="hidden" name="joinTradIds" value=""/>
								<input type="hidden" name="joinTradKzs" value=""/>
							</div>
						</div>
					</div>
					<!-- 公共下部分结束 -->
					
					<!-- 关联工单检索条件 -->
					<div class="row">
						<div class="col-md-4">
							<div class="form-group"><label class="queryInputLabel">银行账号</label>
								<input type="text" name="syhzh" class="form-control">
							</div>
						</div>
						<div class="col-md-4">
							<div class="form-group"><label class="queryInputLabel">关联手机</label>
								<input type="text" name="sglsj" class="form-control">
							</div>
						</div>
						<div class="col-md-4">
							<div class="form-group" style="padding-top: 25px;">
								<button type="button" class="btn btn-warning" id="searchSelOrderBt">检索工单</button>
							</div>
						</div>
					</div>
					<!-- 关联工单检索条件结束 -->
					
					<!-- 关联交易列表 -->
				   	<div class="box-body">
						<table id="iWorkOrderSelGrid_${uuid}_d">
				   		</table>
					</div>
					<!-- 关联交易列表结束 -->
					
					<!-- 提交状态 -->
					<div class="row">
						<div class="col-md-4">
							<div class="form-group"><label>提交状态</label>
								<select class="form-control"  name="gdclzt" check-type="required">
					                <pf:dataDic var="item" dicCode="GDCLZT">
					                    <option value="${item.value}">${item.name}</option>
					                </pf:dataDic>
					            </select>
							</div>
						</div>
					</div>
					<!-- 提交状态结束 -->
					
				</div>
				<div role="tabpanel" class="tab-pane fade am-margin-top-sm" id="${uuid}_formViewTab">
	       	   </form>
			 </div>
		</div>
        <nav class="navbar navbar-default">
		  <div class="container-fluid">
		  	<div class="collapse navbar-collapse">
		  		<ul class="nav navbar-nav navbar-right">
			  		<li>
			  			<button type="button" class="btn btn-primary navbar-btn" id="iWorkOrderFormSaveBt">提交</button>
			  		</li>
			  	</ul>
	        </div>
		  </div>
		</nav>
		<ul class="nav nav-tabs" role="tablist">
				<li role="presentation" class="active">
					<a href="#${uuid}_hisDataTab" role="tab" data-toggle="tab">
						历史工单信息
					</a>
				</li>
		</ul>
		<div class="tab-content">
			<div class="box-body">
				<table id="hisWorkOrderGrid_${uuid}" >
		   		</table>
			</div>
		</div>
</div>
<script type="text/javascript">
	
    $(function () {
    	webUtils.nameSpace("wiseMen.workOrder");
    	//设置业务类型选择事件
    	wiseMen.workOrder.ywlxSelEventAdd=function(){
    		var ywlx = $("div[role=tabpanel]").find("select[name=ywlx]");
    		ywlx.unbind("change");
    		ywlx.change(function(){
	    		var tab = $(this).parents("div[role=tabpanel]");
	    		if($(this).val()=='5'){//风控类
	    			tab.find(".serviceWO").hide();
	    			tab.find(".riskWO").show();
	    			tab.find("select[name=gdclzt]").find('option[value=2]').hide();
	    		}else{//客服类
	    			tab.find(".riskWO").hide();
	    			tab.find(".serviceWO").show();
	    			tab.find("select[name=gdclzt]").find('option[value=2]').show();
	    		}
	    		wiseMen.workOrder.setZywlxOptionAdd($(this));
	    	});
    		//隐藏风控类子类型
    		wiseMen.workOrder.setZywlxOptionAdd(ywlx);
    	}
    	//设置子业务类型选项
    	wiseMen.workOrder.setZywlxOptionAdd=function(ywlx){
    		var tab = ywlx.parents("div[role=tabpanel]");
    		var zywlx = tab.find("select[name=zywlx]");
    		var options = zywlx.find('option');
    		var defaultVal = '';
    		$.each(options,function(index,o){
    			var obj = $(o);
    			if(obj.val().indexOf(ywlx.val()+'-')!=-1){
    				if(defaultVal==''){
    					defaultVal = obj.val();
    				}
    				obj.show();
    			}else{
    				obj.hide();
    			}
    		});
    		zywlx.val(defaultVal);
    	}
    	wiseMen.workOrder.ywlxSelEventAdd();
    	
    	//查看交易详细
    	wiseMen.workOrder.tradingView=function(uuid,rowIndex){
    		var row = $("#iWorkOrderSelGrid_"+uuid+"_d").bootstrapTable("getRowByIndex", rowIndex);
    		var uuid=webUtils.uuid();
    		var d=webUtils.dialog({
    			url:ctx+"/dataModelDefAct/viewTpl.do?dms=DM_TRADING_ORDER&DM_TRADING_ORDER_ID="+row.ID+"&winId="+uuid
    		});
    	}
    	//删除标签页
    	wiseMen.workOrder.delOrder=function(id){
    		$('a[href*='+id+']').parent().remove();
    		$('div[id*='+id+']').remove();
    		$("#orderNav").find('li').first().find('a').trigger('click');
    	}
    	//移除关联交易
    	wiseMen.workOrder.checkJoinAdd=function(obj){
    		var id = $(obj).attr('id');
    		var ddh = $(obj).attr('ddh');
    		var je = $(obj).attr('je');
    		var kz = $(obj).attr('kz');
    		var data = $(obj).parents('div[id*=fieldDataTab]');
    		var trad = data.find("#joinTrad");
    		if($(obj).prop('checked')==true){
    			if(trad.find("#"+id).length==0){
    	    		trad.append('<span id="'+id+'" je="'+je+'" kz="'+kz+'">'+ddh+'<font style="color:red;cursor: pointer;" class="delJoinTrad" title="移除">X</font></span>&nbsp;');
    			}
    		}else{
    			trad.find("#"+id).remove();
    		}
    		wiseMen.workOrder.joinTradJs(trad,data);
    		$(".delJoinTrad").click(function(){
    			var did = $(this).parent().attr('id');
    			$(this).parent().remove();
    			var checkbox = data.find("input[type=checkbox][id="+did+"]");
    			checkbox.prop('checked',false);
    			wiseMen.workOrder.joinTradJs(trad,data);
    		});
    		//搜索历史工单
        	//$("input[name=his_yhzh]").val();
        	//wiseMen.workOrder.loadHisGrid.bootstrapTable("refresh");
    	}
    	//计算关联交易
    	wiseMen.workOrder.joinTradJs=function(trad,data){
    		var ts = trad.find('span');
    		var zje = 0.0;
    		var ids = '';
    		var kzs = '';
    		$.each(ts,function(index,t){
    			zje +=parseFloat($(t).attr('je'));
    			if(ids!=''){
    				ids +=',';
    				kzs +=',';
    			}
    			ids +=$(t).attr('id');
    			kzs +=$(t).attr('kz');
    		});
    		data.find('#tradCount').val(ts.length);
    		data.find('#tradJe').val(zje);
    		data.find('input[name=joinTradIds]').val(ids);
    		data.find('input[name=joinTradKzs]').val(kzs);
    	}
    	
    	//初始化关联交易列表方法    	
    	wiseMen.workOrder.addIndex = 1;
    	wiseMen.workOrder.renderId = '${uuid}';
    	wiseMen.workOrder.loadTableGrid=function(uuid,index){
	    	var iworkOrderSelGrid = $("#iWorkOrderSelGrid_"+uuid+"_d").bootstrapTable({
	        	url:ctx + "/queryDefAction/queryDatas.do?code=DM_TRADING_ORDER",
	        	columns:[
	    			{title: '关联' , field: 'ID' , width: "50px",formatter:function(data, row, index){
	    					return '<input type="checkbox" id="'+row.ID+'" ddh="'+row.YLDDH+'" je="'+row.JYJE+'" kz="'+row.KZ+'" onclick="javascript:wiseMen.workOrder.checkJoinAdd(this);"></input>';
	    				}
	    			},
	    			{title: '开户姓名', field: 'KHXM'},
	    			{title: '交易手机', field: 'JYSJH'},
	    			{title: '银行卡号', field: 'YHZH'},
	    			{title: '银行', field: 'YH'},
	    			{title: '卡种', field: 'KZ',formatter:function(data, row, index){
	                	return wo.getDataDicItemVal('KZ', data);
	                }},
	    			{title: '商店名称', field: 'SDMC'},
	    			{title: '商品描述', field: 'SPMS'},
	                {title: '易联订单号', field: 'YLDDH'},
	                {title: '商户订单号', field: 'SHDDH'},
	                {title: '交易金额', field: 'JYJE'},
	                {title: '人民币金额', field: 'RMBJE'},
	                {title: '交易时间', field: 'JYSJ'},
	                {title: '状态', field: 'DDZT'},
	                {title: '支付结果', field: 'ZFJG'},
	                {title: '详细', field: 'ID',formatter:function(data, row, index){
	                	var btn = '<button data-rowindex="0" type="button" title="查看" class="btn btn-default btn-xs am-margin-left-xs am-margin-vertical-xs inGridOptBtn" onclick="javascript:wiseMen.workOrder.tradingView(\''+uuid+'\',\''+index+'\')"><span class="glyphicon glyphicon-search"></span></button>';
	                	return btn;
	                }}
	        	],
	    	    queryParams: function(d) {
	    	        var yhzh = $("#"+uuid+"_fieldDataTab"+index).find("input[name=syhzh]").val();
	    	        var yjsjh = $("#"+uuid+"_fieldDataTab"+index).find("input[name=sglsj]").val();
	    	        d.searchData = JSON.stringify({YHZH:yhzh,JYSJH:yjsjh});
	    	        return d;
	    	    }
	        });
	        $("#"+uuid+"_fieldDataTab"+index).find("#searchSelOrderBt").click(function(){
	        	iworkOrderSelGrid.bootstrapTable("refresh");
	        });
    	}
    	//初始化第一个工单所关联的交易列表
    	wiseMen.workOrder.loadTableGrid(wiseMen.workOrder.renderId,'');
    	
    	//加载表单初始化数据
    	var id = '${param.id}';
        var winId = '${param.winId}';
        $("#workOrderByUserForm").validation();
        $("form[name=workOrderForm]").validation();
        
        //提交保存数据        
        $("#iWorkOrderFormSaveBt").click(function () {
    		var selJoin = $("input[id=tradCount]");
    		var isSelJoin = true;
    		$.each(selJoin,function(index,obj){
    			if($.trim($(obj).val())=='0'){
    				isSelJoin = false;
    			}
    		});
			var userDataForm=$("#workOrderByUserForm");
			var userDataFormObj=webUtils.formToObj(userDataForm);
			var orderDataForms=$("form[name=workOrderForm]");
			var orderDataFormObj = [];
			$.each(orderDataForms,function(index,form){
				var orderData = webUtils.formToObj($(form));
				orderData.yhkbdyw = wo.join(orderData.yhkbdyw,',');
				orderDataFormObj.push(orderData);
			});
        	if($("#workOrderByUserForm").valid() && $("form[name=workOrderForm]").valid()){
        		if(!isSelJoin){
                    alert("请选择关联的交易记录！");
                    return false;
        		}
        		var tips = "";
            	$.each($(".orderPane"),function(index,o){
            		var obj = $(o);
            		var sel = obj.find("select[name=gdclzt]");
            		tips += obj.attr("label")+"【提交状态："+sel.find("option[value="+sel.val()+"]").text()+"】<br/>";
            	});
            	tips += "确认是否提交？";
            	layer.confirm(tips, {
            		  btn: ['提交','取消'] //按钮
          		}, function(index){
            		$.post(ctx + '/workOrderAct/saveWorkOrder.do',{userDatas:Base64.encode(JSON.stringify(userDataFormObj)),
            				orderDatas:Base64.encode(JSON.stringify(orderDataFormObj))},function (data) {
                            if (data.success) {
                                webUtils.alert("提交成功");
                                top.webUtils.topicPublish("dialog.submit.success."+winId, data);
                            } else {
                            	webUtils.error(data.msg);
                            }
                        }
                    );
            		layer.close(index);
          		}, function(){
          		  
          		});
        	}
        });
        
        $(".addOrderBtnCss").click(function(){
        	wiseMen.workOrder.addIndex++;
        	var uuid=webUtils.uuid();
        	//添加新建工单标签页头
        	var ul = $("#orderNav");
        	var li = '<li role="presentation">'+
							'<a href="#'+uuid+'_fieldDataTab'+wiseMen.workOrder.addIndex+'" role="tab" data-toggle="tab">'+
							'新建工单'+wiseMen.workOrder.addIndex+
							'<span style="color:red" title="删除工单" onclick="javascript:wiseMen.workOrder.delOrder(\''+uuid+'\')">&nbsp;X&nbsp;</span>'+
						'</a>'+
					'</li>';
        	ul.append(li);
        	//拷贝第一工单内容作为新增工单内容
        	var tab = $("#orderTab");
        	var tabPanel =  '<div role="tabpanel" class="tab-pane fade am-margin-top-sx orderPane" id="'+uuid+'_fieldDataTab'+wiseMen.workOrder.addIndex+'" label="新建工单'+wiseMen.workOrder.addIndex+'">'+
        						'<form name="workOrderForm">'+
        							wiseMen.workOrder.firstTabHtml+
        						'</form>'+
	        				'</div>';
        	tabPanel = tabPanel.replace(wiseMen.workOrder.renderId,(wiseMen.workOrder.renderId+wiseMen.workOrder.addIndex));
        	tab.append(tabPanel);
        	//重新初始化新增工单关联交易列表
        	var tab = $('#'+uuid+'_fieldDataTab'+wiseMen.workOrder.addIndex);
        	var tableP = tab.find('.box-body');
        	tableP.empty();
        	tableP.append('<table id="iWorkOrderSelGrid_'+uuid+'_d"></table>');
        	wiseMen.workOrder.loadTableGrid(uuid,wiseMen.workOrder.addIndex);
        	//设置选择业务类型事件
        	wiseMen.workOrder.ywlxSelEventAdd();
        });
        //将第一个工单标签页内容放置页面内存中
        wiseMen.workOrder.firstTabHtml = $("#orderTab").find('div[role=tabpanel]').first().html();
        
        //查询历史工单
        wiseMen.workOrder.loadHisGrid = null;
        wiseMen.workOrder.loadHisData=function(){
        	wiseMen.workOrder.loadHisGrid = $("#hisWorkOrderGrid_${uuid}").bootstrapTable({
        		url:ctx + "/workOrderAct/queryWorkOrderDealList.do?clzts=all",
            	columns:[
        			{field: '_id',checkbox:true},
        			{title: '业务类型', field: 'YWLX',width: "130px",formatter:function(data, row, index){
                    	return wo.getDataDicItemVal('YWLX', data);
                    }},
                    {title: '子业务类型', field: 'ZYWLX',width: "110px",formatter:function(data, row, index){
                    	return wo.getDataDicItemVal('ZYWLX', data);
                    }},
                    {title: '来电号码', field: 'LDHM', width: "120px"},
                    {title: '客户姓名', field: 'KHXM', width: "80px"},
                    {title: '登记时间', field: 'CREATETIME',width: "160px",formatter:function(data, row, index){
                    	return webUtils.parseTimestamp(data, 'yyyy-MM-dd HH:mm:ss');
                    }},
                    {title: '流转时间', field: 'HJSJ',width: "160px",formatter:function(data, row, index){
                    	return webUtils.parseTimestamp(data, 'yyyy-MM-dd HH:mm:ss');
                    }},
                    {title: '当前环节', field: 'HJMC',width: "100px",formatter:function(data, row, index){
                    	var html = '';
                    	if(row.CXLX=='deal'){
        	            	html = data;
        	            	if(row.CLZT=='2'){
        	            		html+='<font color="red" title="暂缓派单">(缓)</font>';
        	            	}
        	            	if(row.SFZT=='1'){
        	            		html+='<font color="red" title="请求释放">(释)</font>';
        	            	}
        	            	if(row.CLZT=='-1'){
        	            		html='暂存';
        	            	}
                    	}else{
                    		if(row.HJZT=='0'){
                    			html = row.DQHJ;
                    		}else{
                    			html = data;
                    		}
                    	}
                    	if(row.CQBJ=='1'){
                    		html+='<font color="red" title="重启原因:'+wo.getDataDicItemVal('CQYY', row.CQYY)+'">(重)</font>';
                    	}
                    	return html;
                    }},
                    {title: '操作', field: 'ID',width: "80px",formatter:function(data, row, index){
                    	var html ='';
                    	html+='<button type="button" class="btn btn-default btn-sm" title="查看" onclick="javascript:wiseMen.workOrder.queryHis('+index+');"><span class="glyphicon glyphicon glyphicon-search"></span></button>';
                    	return html;
                    }}
            	],
        	    queryParams: function(d) {
        	    	var ldhm = '-1';
        	    	if($("input[name=ldhm]").val()!=''){
        	    		ldhm = $("input[name=ldhm]").val();
        	    	}
        	        d.ldhm = ldhm;
        	        return d;
        	    }
            });
        	//搜索历史工单
        	$("input[name=ldhm]").change(function(){
        		wiseMen.workOrder.loadHisGrid.bootstrapTable("refresh");
        	});
        }
        wiseMen.workOrder.loadHisData();
        
    });    
</script>
